﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB;
using HYCodeBase.WinForm;

namespace ElectricDim
{
	public partial class DlgModelLess : System.Windows.Forms.Form
	{
		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		public DlgModelLess(WindowHandle handle)
		{
			base.Icon = Resource.YArchitechIcon;
			this.wHandle = handle;
			this.InitializeComponent();
		}

		public DlgModelLess()
		{
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		protected void turnToRevit()
		{
			if (!base.ClientRectangle.Contains(base.PointToClient(Cursor.Position)))
			{
				int wMsg = 7;
				DlgModelLess.SendMessage(this.wHandle.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
				return;
			}
			base.Focus();
		}

		protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
		{
			int num = 256;
			int num2 = 260;
			if ((msg.Msg == num | msg.Msg == num2) && keyData == Keys.Escape)
			{
				base.Close();
			}
			return false;
		}

		protected void SendESC()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			DlgModelLess.keybd_event((byte)bVk, 0, dwFlags, 0);
			DlgModelLess.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void DlgLampLabel_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.SendESC();
			base.Hide();
			e.Cancel = true;
		}

		private void DlgLampLabel_MouseLeave(object sender, EventArgs e)
		{
			this.turnToRevit();
		}

		private WindowHandle wHandle;
	}
}
